#!/bin/bash
# coding = utf-8
# @Time    : 2024-04-24  11:14:29
# @Author  : zhaosheng@nuaa.edu.cn
# @Describe: .
pt_folder="/VAF_large/pt"
onnx_foldr="/VAF_large/onnx"
pwd_folder=$(pwd)

# Step1 Remove all the python cache files and .vscode folder
echo "# Cleaning up python cache files..."
find . -type d -name "__pycache__" -exec rm -r {} +
find . -type d -name ".vscode" -exec rm -r {} +
find . -name "*.pyc" -exec rm -f {} +

# also rm all build folder and bin folder
# find . -type d -name "build" -exec rm -r {} +
# find . -type d -name "bin" -exec rm -r {} +

# Step2 Check each subdirectory has the README.md file
echo "# Checking each subdirectory has the README.md file..."
for dir in $(ls -d */); do
    if [ ! -f $dir/README.md ]; then
        echo "The README.md file is missing in the $dir directory."
    fi
done

# Step3 Caculate the size of the each file in the current directory (excluding the subdirectories but except the .git folder)
echo "# Calculating the size of the files in the current directory..."
du -ah --max-depth=1 --exclude=.git | sort -rh

# Step4 Caculate .git size
echo "# Calculating the size of the .git folder..."
gitsize=$(du -sh .git | cut -f1)
echo "The size of the .git folder is: $gitsize"

# Step5 link files
echo "# Linking the files..."
# link pt_folder to ./dguard/files/pt if not exist
if [ ! -d "${pwd_folder}/dguard/files/pt" ]; then
    echo "ln -s $pt_folder $pwd_folder/dguard/files"
    ln -s $pt_folder $pwd_folder/dguard/files
fi
# link onnx_folder to ./dgurad/files/onnx if not exist
if [ ! -d "${pwd_folder}/dguard/files/onnx" ]; then
    echo "ln -s $onnx_foldr $pwd_folder/dguard/files"
    ln -s $onnx_foldr $pwd_folder/dguard/files
fi